package com.jwds.digital.bios.business.api.controller.dispatch;

import cn.hutool.json.JSONUtil;
import com.jwds.digital.bios.business.core.constants.DispatchConstant;
import com.jwds.digital.bios.business.core.enums.WarehouseClassification;
import com.jwds.digital.bios.business.core.infrastructure.dto.dispatch.DispatchParameterReqDTO;
import com.jwds.digital.bios.business.core.infrastructure.dto.dispatch.DispatchRevertReqDTO;
import com.jwds.digital.bios.business.core.infrastructure.vo.dispatch.DispatchReceivingMaterialsRespVO;
import com.jwds.digital.bios.business.core.infrastructure.vo.dispatch.DispatchRevertRespVO;
import com.jwds.digital.bios.business.core.infrastructure.vo.feign.FlowBasicRespVO;
import com.jwds.digital.bios.business.service.service.dispatch.IDispatchRevertService;
import com.jwds.tdc.framework.application.lib.BaseResponse;
import com.jwds.tdc.framework.application.lib.page.PageRequest;
import com.jwds.tdc.framework.application.lib.page.PageResponse;
import com.jwds.tdc.framework.cache.service.CacheService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.compress.utils.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * 返料调度 前端控制器
 *
 * @author 林柏云
 * @date 2024-10-24
 */
@Slf4j
@Api(tags = "返料调度")
@RestController
@RequestMapping("/dispatch/revert")
public class DispatchRevertController {

    @Resource
    private IDispatchRevertService service;

    @Autowired
    private CacheService cacheService;

    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查询")
    public BaseResponse<DispatchRevertRespVO> queryById(@PathVariable("id") Long id) {
        DispatchRevertRespVO respVo = service.queryById(id);
        return BaseResponse.success(respVo);
    }

    @PostMapping("/list")
    @ApiOperation(value = "分页查询")
    public BaseResponse<PageResponse<DispatchRevertRespVO>> page(@RequestBody PageRequest<DispatchRevertReqDTO> pageRequest) {
        PageResponse<DispatchRevertRespVO> respVoPage = service.page(pageRequest);
        return BaseResponse.success(respVoPage);
    }
    @PostMapping("/all")
    @ApiOperation(value = "查询全部数据")
    public BaseResponse<List<DispatchRevertRespVO>> list() {
        List<DispatchRevertRespVO> respVoList = service.findAll();
        return BaseResponse.success(respVoList);
    }

    @GetMapping("/allBlastFurnace")
    @ApiOperation(value = "查询指定料仓数据")
    public BaseResponse<List<DispatchRevertRespVO>> listBlastFurnace(String binName) {
        List<DispatchRevertRespVO> respVoList = service.listBlastFurnace(binName);
        return BaseResponse.success(respVoList);
    }
    @GetMapping("/DropDownBox/{destPointion}")
    @ApiOperation(value = "终点下拉框")
    public BaseResponse<List<String>> DropDownBox(@PathVariable String destPointion) {
        List<String> respVoList = service.DropDownBox(destPointion);
        return BaseResponse.success(respVoList);
    }


    @GetMapping("/DestDevice/{destDevice}")
    @ApiOperation(value = "终点设备下拉框")
    public BaseResponse<List<String>> destDevice(@PathVariable String destDevice) {
        List<String> respVoList = service.destDevice(destDevice);
        return BaseResponse.success(respVoList);
    }

    @GetMapping("/OriginDevice")
    @ApiOperation(value = "流程下拉框")
    public BaseResponse<List<String>> originDevice(@RequestBody DispatchRevertReqDTO reqDTO) {
        List<String> respVoList = service.originDevice(reqDTO);
        return BaseResponse.success(respVoList);
    }


    @PostMapping("/Execute")
    @ApiOperation(value = "执行")
    public BaseResponse<DispatchRevertRespVO> Execute(@RequestBody DispatchRevertReqDTO reqDTO) {
        DispatchRevertRespVO respVo = service.execute(reqDTO);
        return BaseResponse.success(respVo);
    }

    @GetMapping("blast_furnace_return_material")
    @ApiOperation(value = "高炉返料")
    public BaseResponse<List<DispatchParameterReqDTO>> BlastFurnaceReturnMaterial() {
        List<DispatchParameterReqDTO> basicStockBinRespVOS = Lists.newArrayList();
        String respVoList = cacheService.getString(DispatchConstant.REDIS_KEY+":" + WarehouseClassification.GLFJFKC);
        if (null != respVoList){
            basicStockBinRespVOS = JSONUtil.toList(respVoList, DispatchParameterReqDTO.class);
        }
        return BaseResponse.success(basicStockBinRespVOS);
    }


    @GetMapping("mineral_powder_warehouse")
    @ApiOperation(value = "矿粉仓返料")
    public BaseResponse<List<DispatchParameterReqDTO>> MineralPowderWarehouse() {
        List<DispatchParameterReqDTO> basicStockBinRespVOS = Lists.newArrayList();
        String respVoList = cacheService.getString(DispatchConstant.REDIS_KEY+":" + WarehouseClassification.KFC);
        if (null != respVoList){
            basicStockBinRespVOS = JSONUtil.toList(respVoList, DispatchParameterReqDTO.class);
        }
        return BaseResponse.success(basicStockBinRespVOS);
    }

    @GetMapping("coking_powder_warehouse")
    @ApiOperation(value = "焦粉仓返料")
    public BaseResponse<List<DispatchParameterReqDTO>> CokingPowderWarehouse() {
        List<DispatchParameterReqDTO> basicStockBinRespVOS = Lists.newArrayList();
        String respVoList = cacheService.getString(DispatchConstant.REDIS_KEY+":" + WarehouseClassification.JFC);
        if (null != respVoList){
            basicStockBinRespVOS = JSONUtil.toList(respVoList, DispatchParameterReqDTO.class);
        }
        return BaseResponse.success(basicStockBinRespVOS);
    }



}
